USE [hungdong2chuaxuly]
GO

/****** Object:  StoredProcedure [dbo].[sp_NVDangKyLichDi]    Script Date: 10/13/2013 21:10:53 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[sp_NVDangKyLichDi]
@manv varchar(10),
@matuyen int,
@maxe int,
@ngaydi datetime
as
begin

	insert into dangkylichdi values(@manv,@matuyen,@maxe,@ngaydi,1);

end
GO

--

CREATE proc [dbo].[sp_NVDangKyLichDiup]
@manv varchar(10),
@matuyen int,
@maxe int,
@ngaydi datetime
as
begin tran
	--insert into dangkylichdi values(@manv,@matuyen,@maxe,@ngaydi,1);
	declare @maloainv int =(select LoaiNV from NhanVien where MaNV=@manv)
	print @maloainv
	if(@maloainv = 2)
	begin
		declare @sltai int=(select SLTaiXeDaDangKi from LichDi where MaTuyen=@matuyen and MaXe=@maxe and NgayDi=@ngaydi)
		set @sltai=@sltai+1
		waitfor delay '0:0:05'
		update LichDi
		set SLTaiXeDaDangKi=@sltai
		where MaTuyen=@matuyen and MaXe=@maxe and NgayDi=@ngaydi
	end
	else
	begin
		declare @slphu int=(select SLPhuLaiDaDangKi from LichDi where MaTuyen=@matuyen and MaXe=@maxe and NgayDi=@ngaydi)
		set @slphu=@slphu+1
		waitfor delay '0:0:05'
		update LichDi
		set SLPhuLaiDaDangKi=@slphu
		where MaTuyen=@matuyen and MaXe=@maxe and NgayDi=@ngaydi
	end
	
commit tran



GO
